package com.gitee.dolt.boot.service;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.util.*;

@RequiredArgsConstructor
public class ServiceCacheRegister {

    private Map<String, IServiceCacheManager> cacheManagerMap;

    public void register(@NonNull String key, @NonNull ServiceCacheManager cacheManager) {
        if (this.cacheManagerMap == null) {
            this.cacheManagerMap = new HashMap<>();
        }
        this.cacheManagerMap.put(key, cacheManager);
    }

    public Collection<IServiceCacheManager> getCacheManagers() {
        return this.cacheManagerMap == null ? Collections.emptyList() : this.cacheManagerMap.values();
    }

    public IServiceCacheManager getCacheManager(String key) {
        return this.cacheManagerMap == null ? null : this.cacheManagerMap.get(key);
    }

}
